package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.system.domain.Drug;
import com.ruoyi.system.domain.DrugVerify;
import com.ruoyi.system.service.IDrugRuleService;
import com.ruoyi.system.service.IDrugService;
import com.ruoyi.system.service.IDrugVerifyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.CourseMapper;
import com.ruoyi.system.domain.Course;
import com.ruoyi.system.service.ICourseService;

/**
 * 病程记录Service业务层处理
 * 
 * @author wmb
 * @date 2020-09-01
 */
@Service
public class CourseServiceImpl implements ICourseService 
{
    @Autowired
    private CourseMapper courseMapper;

    @Autowired
    private IDrugVerifyService  drugVerifyService;

    @Autowired
    private IDrugService drugService;
    /**
     * 查询病程记录
     * 
     * @param id 病程记录ID
     * @return 病程记录
     */
    @Override
    public Course selectCourseById(Long id)
    {
        return courseMapper.selectCourseById(id);
    }

    /**
     * 查询病程记录列表
     * 
     * @param course 病程记录
     * @return 病程记录
     */
    @Override
    public List<Course> selectCourseList(Course course)
    {
        return courseMapper.selectCourseList(course);
    }

    /**
     * 新增病程记录
     * 
     * @param course 病程记录
     * @return 结果
     */
    @Override
    public int insertCourse(Course course)
    {
        return courseMapper.insertCourse(course);
    }

    /**
     * 修改病程记录
     * 
     * @param course 病程记录
     * @return 结果
     */
    @Override
    public int updateCourse(Course course)
    {
        return courseMapper.updateCourse(course);
    }

    /**
     * 批量删除病程记录
     * 
     * @param ids 需要删除的病程记录ID
     * @return 结果
     */
    @Override
    public int deleteCourseByIds(Long[] ids)
    {
        return courseMapper.deleteCourseByIds(ids);
    }

    /**
     * 删除病程记录信息
     * 
     * @param id 病程记录ID
     * @return 结果
     */
    @Override
    public int deleteCourseById(Long id)
    {
        return courseMapper.deleteCourseById(id);
    }


    @Override
    public void insertBatchCource(List<Course> courses){


        for(Course course : courses){


            Drug drug =  drugService.selectDrugByName(course.getDrugName());
            if(drug != null) {
                DrugVerify verify = new DrugVerify();
                verify.setAdmissionId(course.getAdmissionId());
                //verify.setCode(course.);
                verify.setDrugId(drug.getId());
                verify.setDrugName(drug.getName());

                drugVerifyService.insertDrugVerify(verify);
                this.insertCourse(course);

            }
        }



    }
}
